package com.sl.hx.shop.ui.home.activity;

import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.sl.hx.shop.R;
import com.sl.hx.shop.base.BaseActivity;
import com.sl.hx.shop.base.BasePresenter;
import com.sl.hx.shop.bean.CollectGoodsBean;
import com.sl.hx.shop.ui.collect.CollectFragment;
import com.sl.hx.shop.ui.home.adapter.ShopHomeAdapter;
import com.sl.hx.shop.utils.ScreenUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 店铺主页
 */

public class ShopHomeActivity extends BaseActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.icon)
    ImageView icon;
    @BindView(R.id.icon_taobao)
    ImageView iconTaobao;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    private ShopHomeAdapter mShopHomeAdapter;
    private List<CollectGoodsBean> datas;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_shop_home;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        initDatas();
        initrecycle();
    }


    @Override
    protected void initData() {

    }

    private void initrecycle() {
        mShopHomeAdapter = new ShopHomeAdapter(datas);
        mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));
        mRecyclerView.addItemDecoration(new MarginDecoration(mContext));
        mRecyclerView.setAdapter(mShopHomeAdapter);
    }

    private void initDatas() {
        datas = new ArrayList<>();
        datas.add(new CollectGoodsBean(1, R.mipmap.ic_launcher, "新款高端名媛气质绣花圆领修身显瘦百褶打底连衣裙秋冬款"));
        datas.add(new CollectGoodsBean(2, R.mipmap.ic_launcher, "告白气球"));
        datas.add(new CollectGoodsBean(3, R.mipmap.ic_launcher, "夜曲"));
        datas.add(new CollectGoodsBean(4, R.mipmap.ic_launcher, "多种type"));
        datas.add(new CollectGoodsBean(5, R.mipmap.ic_launcher, "多种type"));
        datas.add(new CollectGoodsBean(6, R.mipmap.ic_launcher, "多种type"));
        datas.add(new CollectGoodsBean(7, R.mipmap.ic_launcher, "多种type"));
        datas.add(new CollectGoodsBean(8, R.mipmap.ic_launcher, "多种type"));
    }


    @OnClick({R.id.back, R.id.title})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.title:
                break;
        }
    }

    //recycleview item设置间距
    class MarginDecoration extends RecyclerView.ItemDecoration {
        private int margin;

        public MarginDecoration(Context context) {
            margin = ScreenUtil.dp2px(context,10);
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(margin, margin, margin, margin);
        }
    }
}
